package com.yuke.cloud.service.pmc.service.impl;

import com.yuke.cloud.service.pmc.dao.ProdSpecAttributeMapper;
import com.yuke.cloud.service.pmc.entity.ProdCategoryAttribute;
import com.yuke.cloud.service.pmc.entity.ProdSpecAttribute;
import com.yuke.cloud.service.pmc.service.ProdSpecAttributeService;
import com.yuke.cloud.common.core.support.BaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;


/**
 * Created by zys on 2018/09/27.
 */
@Service
@Transactional
public class ProdSpecAttributeServiceImpl extends BaseService<ProdSpecAttribute> implements ProdSpecAttributeService {
    @Resource
    private ProdSpecAttributeMapper prodSpecAttributeMapper;

    @Override
    public int save(ProdSpecAttribute record) {
        record.setSpecAttributeId(generateId());
        return super.save(record);
    }

    @Override
    public List<ProdSpecAttribute> getProdSpecAttrBySpecId(Long specId) {
        return prodSpecAttributeMapper.getProdSpecAttrBySpecId(specId);
    }

    @Override
    public int deleteBySpecIds(String specIds) {
        return prodSpecAttributeMapper.deleteBySpecIds(Arrays.asList(specIds.split(",")).stream().map(s -> Long.valueOf(s)).collect(Collectors.toList()));
    }

    @Override
    public List<Long> getSpecAttributeIdsByCateAndAttr(List<ProdCategoryAttribute> prodCategoryAttributes) {
        return prodSpecAttributeMapper.getSpecAttributeIdsByCateAndAttr(prodCategoryAttributes);
    }

    @Override
    public int deleteBySpecAttributeIds(List<Long> specAttributeIds) {
        return prodSpecAttributeMapper.deleteBySpecAttributeIds(specAttributeIds);
    }
}
